package com.tantou.java.study;

import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

public class HappensBeforeTest {

    static volatile   boolean stop = false;

    public static void main(String[] args) throws InterruptedException {
        Thread B = new Thread() {
            @Override
            public void run() {
                while (!stop) {
                    System.out.println("线程B执行中");
                }
                System.out.println("线程B停下来了");
            }
        };
        B.start();

        TimeUnit.MILLISECONDS.sleep(5);
        stop = true;
        System.out.println("需要停下来 >>> " + stop);
    }
}
